package com.lxu.jdbcThreadlocal.dao;

import com.lxu.jdbcThreadlocal.utils.JDBCUtil2;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDao2 {

    /**
     * 转出
     *
     * @param userId
     * @param money
     * @throws SQLException
     */
    public void out(String userId, int money) throws SQLException {

        String sqlStr = "update t_user_m t1 set t1.money=t1.money - ? where t1.user_id=?";

        PreparedStatement ps = JDBCUtil2.getConnection().prepareStatement(sqlStr);
        ps.setInt(1, money);
        ps.setString(2, userId);
        ps.executeUpdate();
        JDBCUtil2.release(ps);
    }

    /**
     * 转入
     *
     * @param userId
     * @param money
     * @throws SQLException
     */
    public void in(String userId, int money) throws SQLException {

        String sqlStr = "update t_user_m t1 set t1.money=t1.money + ? where t1.user_id=?";

        PreparedStatement ps = JDBCUtil2.getConnection().prepareStatement(sqlStr);
        ps.setInt(1, money);
        ps.setString(2, userId);
        ps.executeUpdate();
        JDBCUtil2.release(ps);
    }
}
